package util

import (
	"crypto/rand"
	"encoding/hex"
)

// UUIDv4 generates a version 4 (random) UUID.
func UUIDv4() (string, error) {
	b := make([]byte, 16)
	_, err := rand.Read(b)
	if err != nil {
		return "", err
	}
	// set version
	b[6] = (b[6] & 0x0f) | 0x40
	// set variant
	b[8] = (b[8] & 0x3f) | 0x80
	return hex.EncodeToString(b), nil
}
